package com.ogawa.a7517.fragment;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ogawa.a7517.Constant;
import com.ogawa.a7517.R;
import com.ogawa.a7517.bean.DeviceStateBean;
import com.ogawa.a7517.bean.MassageArmchair;

public class AreaMassageFragment extends BaseFragment implements View.OnClickListener {
    private TextView tvYaobu, tvHand, tvLeg, tvNeck, tvWaist;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_area_massage;
    }

    @Override
    public void initView(View view) {
        tvYaobu = view.findViewById(R.id.tv_yaobu);
        tvYaobu.setOnClickListener(this);
        tvHand = view.findViewById(R.id.tv_hand);
        tvHand.setOnClickListener(this);
        tvLeg = view.findViewById(R.id.tv_leg);
        tvLeg.setOnClickListener(this);
        tvNeck = view.findViewById(R.id.tv_neck_shoulder);
        tvNeck.setOnClickListener(this);
        tvWaist = view.findViewById(R.id.tv_waist);
        tvWaist.setOnClickListener(this);
    }

    @Override
    public void onStart() {
        super.onStart();
        setTitle(getString(R.string.area_masssage));
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (view.isSelected()) {
            judgeToWhere(false);
            return;
        }
        if (id == R.id.tv_yaobu) {
            activity7517.publish(Constant.AUTO_PROGRAM, "18");
        } else if (id == R.id.tv_hand) {
            activity7517.publish(Constant.AUTO_PROGRAM, "19");
        } else if (id == R.id.tv_leg) {
            activity7517.publish(Constant.AUTO_PROGRAM, "21");
        } else if (id == R.id.tv_neck_shoulder) {
            activity7517.publish(Constant.AUTO_PROGRAM, "17");
        } else if (id == R.id.tv_waist) {
            activity7517.publish(Constant.AUTO_PROGRAM, "20");
        }
    }

    @Override
    public void deviceStateChange() {
        super.deviceStateChange();
        DeviceStateBean deviceStatusBean = MassageArmchair.getInstance().getDeviceStatusBean();
        if (deviceStatusBean != null) {
            DeviceStateBean.FunctionsBean.AutoProgramBean autoProgram = deviceStatusBean.getFunctions().getAutoProgram();
            if (autoProgram != null) {
                int auto = Integer.parseInt(autoProgram.getModelValue());
                tvNeck.setSelected(auto == 17);
                tvYaobu.setSelected(auto == 18);
                tvHand.setSelected(auto == 19);
                tvWaist.setSelected(auto == 20);
                tvLeg.setSelected(auto == 21);
            }
        }
    }
}
